﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;

namespace Himp.Outpatient
{
    public class ClinicItemManager : DomainService
    {
        private readonly IRepository<ClinicItemRecord, Guid> _clinicItemRecordRepository;
        private readonly IRepository<OtpRgstRec, Guid> _clinicRegistrationRepository;
        private readonly IRepository<ClinicItem, Guid> _clinicItemRepository;

        public ClinicItemManager(IRepository<ClinicItemRecord, Guid> clinicItemRecordRepository
            , IRepository<OtpRgstRec, Guid> clinicRegistrationRepository
            , IRepository<ClinicItem, Guid> clinicItemRepository)
        {
            _clinicItemRecordRepository = clinicItemRecordRepository;
            _clinicRegistrationRepository = clinicRegistrationRepository;
            _clinicItemRepository = clinicItemRepository;
        }

        /// <summary>
        /// 创建检治项目记录
        /// </summary>
        /// <param name="regiCode"></param>
        /// <param name="clinicItemRecord"></param>
        public async Task<ClinicItemRecord> CreateClinicItemRecord(string regiCode, ClinicItemRecord clinicItemRecord)
        {
            var clinicRegistration = await _clinicRegistrationRepository.GetAsync(c => c.MdtrtSn == regiCode);
            clinicItemRecord.BeginDate = DateTime.Now.Date;
            //clinicItemRecord.ClinicPatientId = clinicRegistration.ClinicPatientId;
            //clinicItemRecord.ClinicRegistrationId = clinicRegistration.Id;
            //clinicItemRecord.PsnName = clinicRegistration.PsnName;
            //clinicItemRecord.Gender = clinicRegistration.Gender;
            clinicItemRecord.IptOtpNo = clinicRegistration.OtpNo;

            return clinicItemRecord;
        }

        public async Task<ClinicItemRecordDetail> CreateClinicItemRecordDetail(ClinicItemRecordDetail clinicItemRecordDetail)
        {
            var clinicItem = await _clinicItemRepository.GetAsync(c => c.ClinicItemValue == clinicItemRecordDetail.ClinicItemValue);
            clinicItemRecordDetail.Price = clinicItemRecordDetail.Price;
            return clinicItemRecordDetail;
        }
    }
}
